Looking at 04 - JavaScript to update a Node.ipynb, we can reuse most of that code to add an IFrame that we can reference later. At this point we do not need to update the IFrame, but it helps to have the scaffolding in place.
At this point we'll just include a static IFrame that points to a fixed URL (https://soasta.github.io/julia-d3-tutorial/d3/06-data-driven-bars.html).
You may need to change this URL to your own if you've cloned the github
repository and are working on your own copy.
In [4]:
function createIFrame()
displayid = "demo-iframe-" * string(rand())
display(
"text/html",
"""
<!-- First create an empty iframe that's 500px high and has this id -->
<iframe
id="$(displayid)"
height="500"
style="border:none;"
src="about:blank">
</iframe>
<!-- Next create a JavaScript function with the same name as the node -->
<script>
window["$(displayid)"] = function(url) {
var iframe = document.getElementById("$(displayid)");
if(iframe) {
iframe.width = iframe.parentNode.offsetWidth * 0.99;
iframe.src = url;
}
};
</script>
"""
)
return displayid
end
Out[4]:
display
calldisplayid
that we can use later to update the iframeWe'll also add another function, this one is just a Julia encapsulation of a JavaScript function to change the iframe's URL
In [5]:
function updateIFrame(displayid, url)
display(
"text/html",
"""<script>window["$(displayid)"]("$(url)");</script>"""
)
end
Out[5]:
In [8]:
id = createIFrame()
updateIFrame(id, "https://soasta.github.io/julia-d3-tutorial/d3/06-data-driven-bars.html")
In [9]:
updateIFrame(id, "https://soasta.github.io/julia-d3-tutorial/d3/05-data-driven-documents.html")
In [ ]: